package api

import (
	"chat/api/handler"
	"chat/api/middleware"
	"chat/consts"
	"github.com/gin-gonic/gin"
	"github.com/share309/gojwt"
)

func LoadRoutes(r *gin.Engine) {
	r.GET("/ping", handler.Ping)
	r.Use(middleware.Cors())
	api := r.Group("/api")
	{
		user := api.Group("/user")
		{
			user.POST("/register", handler.Register)
			user.POST("/login", handler.Login)

			user.POST("/upload", handler.Upload)
			user.Use(gojwt.JWTAuth(consts.JWT_KEY))
			user.GET("/list", handler.GetUserList)
		}
		chat := api.Group("/chat")
		{
			chat.Use(gojwt.JWTAuth(consts.JWT_KEY))
			chat.GET("/ws", handler.Chat)
			chat.GET("/list", handler.GetHistoryList)
		}
		admin := api.Group("/admin")
		{
			admin.POST("/sendMessage", handler.SendAdminMessage)
		}
	}
}
